﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;

namespace Feifansoft.Core.Common.Result
{
    /// <summary>
    /// 操作结果
    /// </summary>
    public class Result
    {
        /// <summary>
        /// 操作状态
        /// </summary>
        [JsonPropertyName("status")]
        public bool Status { get; set; }

        /// <summary>
        /// 操作信息
        /// </summary>
        [JsonPropertyName("message")]
        public string Message { get; set; }

        /// <summary>
        /// 操作成功
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="data"></param>
        /// <returns></returns>
        public static Result<T> Successed<T>(T data)
        {
            return new Result<T>
            {
                Status = true,
                Data = data
            };
        }
        
        /// <summary>
        /// 操作失败
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static Result Failed(string message)
        {
            return new Result
            {
                Status = false,
                Message = message
            };
        }
    }

    /// <summary>
    /// 操作结果
    /// </summary>
    public class Result<T> : Result
    {
        [JsonPropertyName("data")]
        public T Data { get; set; }
    }
}